<%--                                                                       --%>
<%-- Copyright (c) 2003 BroadVision, Inc.  All rights reserved.            --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries. Additionally, IONA    --%>
<%-- and Orbix are trademarks of IONA Technologies, Ltd.  RSA, MD5, and    --%>
<%-- RC2 are trademarks of RSA Data Security, Inc.                         --%>
<%--                                                                       --%>

<%@ page import =  "java.util.HashMap,
                    org.apache.commons.beanutils.PropertyUtils,
                    org.apache.struts.validator.DynaValidatorForm,
                    com.broadvision.web.util.ViewDynaBean,
                    java.util.List"
%>

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<script language="javascript">

  function doStop() {
    if ( confirm('<bean:message key="bp.user.delegation.confirm.stop" bundle="bp.messages"/>') ){
      return true;
    }
    return false;
  }
  
  function doDelete() {
    if ( confirm('<bean:message key="bp.user.delegation.confirm.delete" bundle="bp.messages"/>') ){
      return true;
    }
    return false;
  }
  
</script>
<%
  java.util.HashMap map = new java.util.HashMap();
  DynaValidatorForm userDelegationListForm = (DynaValidatorForm) request.getAttribute("userDelegationListForm");
  map.put("userId", (Long) PropertyUtils.getSimpleProperty(userDelegationListForm, "userId"));
  pageContext.setAttribute("pagetabParam", map, PageContext.PAGE_SCOPE);
%>

<table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" summary="content area">
  <tr>
    <td valign="top" width="100%">
      <div class="pageTitle">
        <bean:write name="userDelegationListView" property="fullName"/>
      </div> 

      <!-- pageTab -->
      <div class="errorMessage"><html:errors bundle="bp.messages"/></div>
      <%@include file="/mc/common/pagetab.jsp" %>
      <!-- end of PageTab -->			

        <div class="globalButtonWrap" align="right">
          <html:form action="/bp/delegationList.do">
            <html:hidden property="userId" />

            <b><bean:message key="bp.user.userDelegationListBody.label.show" bundle="bp.messages"/></b>&nbsp;
            <%
              String selectedValue = (String) PropertyUtils.getSimpleProperty(userDelegationListForm, "timeFilter");
            %>
            <html:select property="timeFilter" value="<%=selectedValue
%>" size="1">
              <html:option key="bp.user.userDelegationListBody.option.current" value="CURRENT" bundle="bp.messages"/>
              <html:option key="bp.user.userDelegationListBody.option.future" value="FUTURE" bundle="bp.messages"/>
              <html:option key="bp.user.userDelegationListBody.option.past" value="PAST" bundle="bp.messages"/>
              <html:option key="bp.user.userDelegationListBody.option.all" value="ALL" bundle="bp.messages"/>
            </html:select>&nbsp;
            <html:submit property="gotoBtn" styleClass="inputButton">
              <bean:message key="button.goto" bundle="bp.messages"/>
            </html:submit>
          </html:form>
        </div>

        <html:form action="/bp/taskDelegateNew.do">
          <html:hidden name="userDelegationListForm" property="userId" />
          <html:hidden name="userDelegationListForm" property="timeFilter" />
          <html:hidden property="fromSet" value="true"/>
	  <html:hidden property="forwardAction" value="/bp/delegationList.do"/>

          <div class="pageSubtitle">
            <span class="left">
              <bean:message key="bp.user.userDelegationListBody.pageSubtitle.task" bundle="bp.messages"/>
            </span>
            <span class="right">
              <logic:equal name="userDelegationListView" property="canEditTaskDelegations" value="true">
                <html:submit styleClass="titleButton" property="submitBtn">
                  <bean:message key="button.delegateTasks" bundle="bp.messages"/>
                </html:submit>&nbsp;
              </logic:equal>
            </span>
          </div> 
        </html:form>

        <%
          ViewDynaBean userDelegationListView = (ViewDynaBean) request.getAttribute("userDelegationListView");
          List taskDelegatorList = (List) PropertyUtils.getSimpleProperty(userDelegationListView, "taskDelegatorList");
          int taskDelegatorListLength = (taskDelegatorList == null) ? 0 : taskDelegatorList.size();
          List taskDelegateList = (List) PropertyUtils.getSimpleProperty(userDelegationListView, "taskDelegateList");
          int taskDelegateListLength = (taskDelegateList == null) ? 0 : taskDelegateList.size();

          int taskDelegationTotalLength = taskDelegatorListLength + taskDelegateListLength;
        %>

        <table class="dataTable" border="0" cellspacing="1" cellpadding="2" summary="task delegations table" width="100%">
          <tr class="listHeader">
            <th id="From" align="left"><bean:message key="bp.user.userDelegationListBody.header.from" bundle="bp.messages"/></th>
            <th id="DelegateTo" align="left"><bean:message key="bp.user.userDelegationListBody.header.delegateTo" bundle="bp.messages"/></th>
            <th id="Start" align="left"><bean:message key="bp.user.userDelegationListBody.header.start" bundle="bp.messages"/></th>
            <th id="End" align="left"><bean:message key="bp.user.userDelegationListBody.header.end" bundle="bp.messages"/></th>
            <th id="Reasons" align="left"><bean:message key="bp.user.userDelegationListBody.header.reasons" bundle="bp.messages"/></th>
            <th id="Actions" align="left"><bean:message key="bp.user.userDelegationListBody.header.actions" bundle="bp.messages"/></th>
          </tr>
          <% if (taskDelegationTotalLength == 0) { %>
            <tr class="listEven">
              <td colspan=6 align="center"><bean:message key="bp.user.userDelegationListBody.noDelegations" bundle="bp.messages"/></td>
            </tr>
          <% } //END if (taskDelegationTotalLength == 0) 
             int totalIndex = 0; %>
          <logic:notEmpty name="userDelegationListView" property="taskDelegatorList">
            <logic:iterate id="oneDelegation" name="userDelegationListView" property="taskDelegatorList" indexId="index">
              <tr class='<%= totalIndex % 2 == 0 ? "listEven" : "listOdd"%>'>
                <td headers="From">
                  <b><bean:write name="oneDelegation" property="delegatorName" /></b>
                </td>
                <td headers="DelegateTo">
                    <bean:write name="oneDelegation" property="delegateName"/>
                </td>
                <td headers="Start">
                  <logic:equal name="oneDelegation" property="showStartTime" value="true">
                    <bean:write name="oneDelegation" property="start" formatKey="format.datetime.short" bundle="mc.messages"/>&nbsp;
                  </logic:equal>
                  <logic:equal name="oneDelegation" property="showStartTime" value="false">
                    <bean:write name="oneDelegation" property="start" formatKey="format.datetime.short" bundle="mc.messages"/>&nbsp;
                  </logic:equal>
                </td>
                <td headers="End">
                  <logic:equal name="oneDelegation" property="showEndTime" value="true">
                    <bean:write name="oneDelegation" property="end" formatKey="format.datetime.short" bundle="mc.messages"/>&nbsp;
                  </logic:equal>
                  <logic:equal name="oneDelegation" property="showEndTime" value="false">
                    <bean:write name="oneDelegation" property="end" formatKey="format.datetime.short" bundle="mc.messages"/>&nbsp;
                  </logic:equal>
                </td>
                <td headers="Reasons">
                  <bean:write name="oneDelegation" property="description" />&nbsp;
                </td>
                <td nowrap align="left" headers="Actions">
                  <logic:equal name="userDelegationListView" property="canEditTaskDelegations" value="true">
                    <logic:equal name="oneDelegation" property="canEdit" value="true">
                      <html:link page="/bp/taskDelegationEdit.do" name="oneDelegation" property="urlParams">
                        <img src="<%=request.getContextPath()%>/bp/images/action/icon_edit.gif" width="15" height="15" border="0" alt='<bean:message key="image.alt.edit" bundle="bp.messages"/>' title='<bean:message key="image.alt.edit" bundle="bp.messages"/>' >
                      </html:link>
                    </logic:equal>
                    <logic:equal name="oneDelegation" property="canDelete" value="true">
                      <html:link page="/bp/userDelegationDelete.do" name="oneDelegation" property="urlParams" onclick="return doDelete();">
                        <img src="<%=request.getContextPath()%>/bp/images/action/icon_delete.gif" width="15" height="15" border="0" alt='<bean:message key="image.alt.delete" bundle="bp.messages"/>' title='<bean:message key="image.alt.delete" bundle="bp.messages"/>' >
                      </html:link>
                    </logic:equal>
                    <logic:equal name="oneDelegation" property="canStop" value="true">
                      <html:link page="/bp/userDelegationStop.do" name="oneDelegation" property="urlParams" onclick="return doStop();">
                        <img src="<%=request.getContextPath()%>/bp/images/action/icon_delete.gif" width="15" height="15" border="0" alt='<bean:message key="image.alt.stop" bundle="bp.messages"/>' title='<bean:message key="image.alt.stop" bundle="bp.messages"/>' >
                      </html:link>
                    </logic:equal>
                  </logic:equal>
                </td>
              </tr>
              <% totalIndex++; %>
            </logic:iterate>
          </logic:notEmpty>

          <logic:notEmpty name="userDelegationListView" property="taskDelegateList">
            <logic:iterate id="oneDelegation" name="userDelegationListView" property="taskDelegateList" indexId="index">
              <tr class='<%= totalIndex % 2 == 0 ? "listEven" : "listOdd"%>'>
                <td headers="From">
                    <bean:write name="oneDelegation" property="delegatorName"/>
                </td>
                <td headers="DelegateTo">
                  <b><bean:write name="oneDelegation" property="delegateName" /></b>
                </td>
                <td headers="Start">
                  <logic:equal name="oneDelegation" property="showStartTime" value="true">
                    <bean:write name="oneDelegation" property="start" formatKey="format.datetime.short" bundle="mc.messages"/>&nbsp;
                  </logic:equal>
                  <logic:equal name="oneDelegation" property="showStartTime" value="false">
                    <bean:write name="oneDelegation" property="start" formatKey="format.datetime.short" bundle="mc.messages"/>&nbsp;
                  </logic:equal>
                </td>
                <td headers="End">
                  <logic:equal name="oneDelegation" property="showEndTime" value="true">
                    <bean:write name="oneDelegation" property="end" formatKey="format.datetime.short" bundle="mc.messages"/>&nbsp;
                  </logic:equal>
                  <logic:equal name="oneDelegation" property="showEndTime" value="false">
                    <bean:write name="oneDelegation" property="end" formatKey="format.datetime.short" bundle="mc.messages"/>&nbsp;
                  </logic:equal>
                </td>
                <td headers="Reasons">
                  <bean:write name="oneDelegation" property="description" />&nbsp;
                </td>
                <td nowrap align="left" headers="Actions">
                  <logic:equal name="userDelegationListView" property="canEditTaskDelegations" value="true">
                    <logic:equal name="oneDelegation" property="canDelete" value="true">
                      <html:link page="/bp/userDelegationDelete.do" name="oneDelegation" property="urlParams" onclick="return doDelete();">
                        <img src="<%=request.getContextPath()%>/bp/images/action/icon_delete.gif" width="15" height="15" border="0" alt='<bean:message key="image.alt.delete" bundle="bp.messages"/>' title='<bean:message key="image.alt.delete" bundle="bp.messages"/>' >
                      </html:link>
                    </logic:equal>
                    <logic:equal name="oneDelegation" property="canStop" value="true">
                      <html:link page="/bp/userDelegationStop.do" name="oneDelegation" property="urlParams" onclick="return doStop();">
                        <img src="<%=request.getContextPath()%>/bp/images/action/icon_delete.gif" width="15" height="15" border="0" alt='<bean:message key="image.alt.stop" bundle="bp.messages"/>' title='<bean:message key="image.alt.stop" bundle="bp.messages"/>' >
                      </html:link>
                    </logic:equal>
                  </logic:equal>
                </td>
              </tr>
              <% totalIndex++; %>
            </logic:iterate>
          </logic:notEmpty>

        </table>

        <html:form action="/bp/roleDelegateNew.do">
          <html:hidden name="userDelegationListForm" property="userId" />
          <html:hidden name="userDelegationListForm" property="timeFilter" />
          <html:hidden property="fromSet" value="true"/>
	  <html:hidden property="forwardAction" value="/bp/delegationList.do"/>

          <div class="pageSubtitle">
            <span class="left">
              <bean:message key="bp.user.userDelegationListBody.pageSubtitle.processManager" bundle="bp.messages"/>
            </span>
            <span class="right">
              <logic:equal name="userDelegationListView" property="canEditProcessManagerDelegations" value="true">
                <html:submit styleClass="titleButton" property="submitBtn">
                  <bean:message key="button.delegateRole" bundle="bp.messages"/>
                </html:submit>&nbsp;
              </logic:equal>
            </span>
          </div> 
        </html:form>

        <%
	 List processManagerDelegatorList = (List) PropertyUtils.getSimpleProperty(userDelegationListView, "processManagerDelegatorList");
         int processManagerDelegatorListLength = (processManagerDelegatorList == null) ? 0 : processManagerDelegatorList.size();
         List processManagerDelegateList = (List) PropertyUtils.getSimpleProperty(userDelegationListView, "processManagerDelegateList");
         int processManagerDelegateListLength = (processManagerDelegateList == null) ? 0 : processManagerDelegateList.size();

         int processManagerDelegationTotalLength = processManagerDelegatorListLength + processManagerDelegateListLength;
        %>

        <table class="dataTable" border="0" cellspacing="1" cellpadding="2" summary="processManager delegations table" width="100%">
          <tr class="listHeader">
            <th id="From" align="left"><bean:message key="bp.user.userDelegationListBody.header.from" bundle="bp.messages"/></th>
            <th id="DelegateTo" align="left"><bean:message key="bp.user.userDelegationListBody.header.delegateTo" bundle="bp.messages"/></th>
            <th id="Start" align="left"><bean:message key="bp.user.userDelegationListBody.header.start" bundle="bp.messages"/></th>
            <th id="End" align="left"><bean:message key="bp.user.userDelegationListBody.header.end" bundle="bp.messages"/></th>
            <th id="Reasons" align="left"><bean:message key="bp.user.userDelegationListBody.header.reasons" bundle="bp.messages"/></th>
            <th id="Actions" align="left"><bean:message key="bp.user.userDelegationListBody.header.actions" bundle="bp.messages"/></th>
          </tr>
          <% if (processManagerDelegationTotalLength == 0) { %>
            <tr class="listEven">
              <td colspan=6 align="center"><bean:message key="bp.user.userDelegationListBody.noDelegations" bundle="bp.messages"/></td>
            </tr>
          <% } //END if (processManagerDelegationTotalLength == 0) 
             totalIndex = 0; %>
          <logic:notEmpty name="userDelegationListView" property="processManagerDelegatorList">
            <logic:iterate id="oneDelegation" name="userDelegationListView" property="processManagerDelegatorList" indexId="index">
              <tr class='<%= totalIndex % 2 == 0 ? "listEven" : "listOdd"%>'>
                <td headers="From">
                  <b><bean:write name="oneDelegation" property="delegatorName" /></b>
                </td>
                <td headers="DelegateTo">
                    <bean:write name="oneDelegation" property="delegateName"/>
                </td>
                <td headers="Start">
                  <logic:equal name="oneDelegation" property="showStartTime" value="true">
                    <bean:write name="oneDelegation" property="start" formatKey="format.datetime.short" bundle="mc.messages"/>&nbsp;
                  </logic:equal>
                  <logic:equal name="oneDelegation" property="showStartTime" value="false">
                    <bean:write name="oneDelegation" property="start" formatKey="format.datetime.short" bundle="mc.messages"/>&nbsp;
                  </logic:equal>
                </td>
                <td headers="End">
                  <logic:equal name="oneDelegation" property="showEndTime" value="true">
                    <bean:write name="oneDelegation" property="end" formatKey="format.datetime.short" bundle="mc.messages"/>&nbsp;
                  </logic:equal>
                  <logic:equal name="oneDelegation" property="showEndTime" value="false">
                    <bean:write name="oneDelegation" property="end" formatKey="format.datetime.short" bundle="mc.messages"/>&nbsp;
                  </logic:equal>
                </td>
                <td headers="Reasons">
                  <bean:write name="oneDelegation" property="description" />&nbsp;
                </td>
                <td nowrap align="left" headers="Actions">
                  <logic:equal name="userDelegationListView" property="isProcessManager" value="true">
                    <logic:equal name="oneDelegation" property="canEdit" value="true">
                      <html:link page="/bp/roleDelegationEdit.do" name="oneDelegation" property="urlParams">
                        <img src="<%=request.getContextPath()%>/bp/images/action/icon_edit.gif" width="15" height="15" border="0" alt='<bean:message key="image.alt.edit" bundle="bp.messages"/>' title='<bean:message key="image.alt.edit" bundle="bp.messages"/>' >
                      </html:link>
                    </logic:equal>
                    <logic:equal name="oneDelegation" property="canDelete" value="true">
                      <html:link page="/bp/userDelegationDelete.do" name="oneDelegation" property="urlParams" onclick="return doDelete();">
                        <img src="<%=request.getContextPath()%>/bp/images/action/icon_delete.gif" width="15" height="15" border="0" alt='<bean:message key="image.alt.delete" bundle="bp.messages"/>' title='<bean:message key="image.alt.delete" bundle="bp.messages"/>' >
                      </html:link>
                    </logic:equal>
                    <logic:equal name="oneDelegation" property="canStop" value="true">
                      <html:link page="/bp/userDelegationStop.do" name="oneDelegation" property="urlParams" onclick="return doStop();">
                        <img src="<%=request.getContextPath()%>/bp/images/action/icon_delete.gif" width="15" height="15" border="0" alt='<bean:message key="image.alt.stop" bundle="bp.messages"/>' title='<bean:message key="image.alt.stop" bundle="bp.messages"/>' >
                      </html:link>
                    </logic:equal>
                  </logic:equal>
                </td>
              </tr>
              <% totalIndex++; %>
            </logic:iterate>
          </logic:notEmpty>

          <logic:notEmpty name="userDelegationListView" property="processManagerDelegateList">
            <logic:iterate id="oneDelegation" name="userDelegationListView" property="processManagerDelegateList" indexId="index">
              <tr class='<%= totalIndex % 2 == 0 ? "listEven" : "listOdd"%>'>
                <td headers="From">
                    <bean:write name="oneDelegation" property="delegatorName"/>
                </td>
                <td headers="DelegateTo">
                  <b><bean:write name="oneDelegation" property="delegateName" /></b>
                </td>
                <td headers="Start">
                  <logic:equal name="oneDelegation" property="showStartTime" value="true">
                    <bean:write name="oneDelegation" property="start" formatKey="format.datetime.short" bundle="mc.messages"/>&nbsp;
                  </logic:equal>
                  <logic:equal name="oneDelegation" property="showStartTime" value="false">
                    <bean:write name="oneDelegation" property="start" formatKey="format.datetime.short" bundle="mc.messages"/>&nbsp;
                  </logic:equal>
                </td>
                <td headers="End">
                  <logic:equal name="oneDelegation" property="showEndTime" value="true">
                    <bean:write name="oneDelegation" property="end" formatKey="format.datetime.short" bundle="mc.messages"/>&nbsp;
                  </logic:equal>
                  <logic:equal name="oneDelegation" property="showEndTime" value="false">
                    <bean:write name="oneDelegation" property="end" formatKey="format.datetime.short" bundle="mc.messages"/>&nbsp;
                  </logic:equal>
                </td>
                <td headers="Reasons">
                  <bean:write name="oneDelegation" property="description" />&nbsp;
                </td>
                <td nowrap align="left" headers="Actions">
                  <logic:equal name="userDelegationListView" property="isProcessManager" value="true">
                    <logic:equal name="oneDelegation" property="canDelete" value="true">
                      <html:link page="/bp/userDelegationDelete.do" name="oneDelegation" property="urlParams" onclick="return doDelete();">
                        <img src="<%=request.getContextPath()%>/bp/images/action/icon_delete.gif" width="15" height="15" border="0" alt='<bean:message key="image.alt.delete" bundle="bp.messages"/>' title='<bean:message key="image.alt.delete" bundle="bp.messages"/>' >
                      </html:link>
                    </logic:equal>
                    <logic:equal name="oneDelegation" property="canStop" value="true">
                      <html:link page="/bp/userDelegationStop.do" name="oneDelegation" property="urlParams" onclick="return doStop();">
                        <img src="<%=request.getContextPath()%>/bp/images/action/icon_delete.gif" width="15" height="15" border="0" alt='<bean:message key="image.alt.stop" bundle="bp.messages"/>' title='<bean:message key="image.alt.stop" bundle="bp.messages"/>' >
                      </html:link>
                    </logic:equal>
                  </logic:equal>
                </td>
              </tr>
              <% totalIndex++; %>
            </logic:iterate>
          </logic:notEmpty>
        </table>
    </td>
  </tr>
</table>


